package ontology;



import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;

public class InteractionTypeFactory extends InteractionTypeSet {


    public InteractionTypeFactory() {

        for (HivProt hivProt : EnumSet.allOf(HivProt.class)) {
            for (InteractionVerb verb : EnumSet.allOf(InteractionVerb.class)) {
                InteractionType t = new InteractionType(verb, hivProt);
                this.add(t);
            }
        }

    }

    public InteractionType getType(InteractionVerb verb, HivProt hivProt) {

        InteractionType intType = new InteractionType(verb, hivProt);
        int index = this.indexOf(intType);
        return this.get(index);
    }

    public InteractionType getType(InteractionType intType) {


        int index = this.indexOf(intType);
        return this.get(index);

    }

    public int getIndexOf(InteractionVerb verb, HivProt hivProt) {
        InteractionType intType = new InteractionType(verb, hivProt);
        int index = this.indexOf(intType);
        return index;
    }
    
    public int getIndexOf(InteractionType intType) {
        int index = this.indexOf(intType);
        return index;
    }

    public String getInteractionTypesId(List<InteractionType> types){
        ArrayList<Integer> indexes = new ArrayList<Integer>();
        for(InteractionType t :types){
            indexes.add(this.getIndexOf(t));
        }
        Collections.sort(indexes);
        StringBuffer output = new StringBuffer();
        for (int i = 0; i < indexes.size(); i++) {
            Integer integer = indexes.get(i);
            output.append(".");
            output.append(integer.toString());

        }
        output.append(".");
        return output.toString();
    }

    public List<InteractionType> getInteractionTypesFromIds(String idString){
//        System.out.println(idString);
        String split[] = idString.split("[.]");
        ArrayList<InteractionType> types = new ArrayList();
        for (int i = 1; i < split.length; i++) {
            types.add(this.get(Integer.parseInt(split[i])));
            

        }
        return types;
    }

    

}

    
